<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                >

    <f:subview id="cadastroVersaoEmbutido" rendered="#{fluxoExibicaoCadastro.exibirCadastroVersao}">
        <h:panelGrid columns="1" styleClass="center">
            <h:panelGroup id="grupCadVersao" styleClass="esquerda">
                <h:form id="formCadVersao" styleClass="formularioFundo">
                    <h:panelGrid columns="3" id="pai" styleClass="bvb-font">
                        <f:facet name="header">
                            <h:outputText value="#{msg.cadVersaoPanelGridTitle}" styleClass="formularioTitle"/>
                        </f:facet>

                        <h:outputLabel value="#{msg.versao}:" id="labelVersao"
                                       title="#{msg.titleNomeCadVersao}"/>
                        <p:inputText value="#{cadastroVersao.versaoCadastro.nome}" id="nomeCad" required="true"
                                     requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titleNomeCadVersao}"
                                     label="#{msg.versao}" maxlength="50" size="50">
                            <f:validateLength minimum="3" maximum="50"/>
                        </p:inputText>
                        <p:message for="nomeCad"/>

                        <h:outputLabel value="#{msg.urlCertificacao}:" id="labelurlCertificacao"
                                       title="#{msg.titleUrlCertificacao}"/>
                        <p:inputText value="#{cadastroVersao.versaoCadastro.urlSiteOficial}" id="urlCertificacaoCad" required="true"
                                     requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titleUrlCertificacao}"
                                     label="#{msg.urlCertificacao}" maxlength="255" size="50">
                            <f:validateLength minimum="3" maximum="255"/>
                            <f:converter converterId="urlConversor"/>
                            <f:validator validatorId="urlValidador"/>
                        </p:inputText>
                        <p:message for="urlCertificacaoCad"/>

                        <h:outputLabel value="#{msg.mediaCobrada}: %" id="labelmediaCobrada"
                                       title="#{msg.titleMediaCadVersao}"/>
                        <p:inputText label="#{msg.mediaCobrada}" value="#{cadastroVersao.versaoCadastro.notaParaPassar}" id="mediaCad"
                                     title="#{msg.titleMediaCadVersao}" size="20" required="true" requiredMessage="#{msg.campoObrigatorio}">
                            <f:validateDoubleRange maximum="100.00" minimum="0.10"/>
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                        </p:inputText>
                        <p:message for="mediaCad"/>

                        <h:outputLabel value="#{msg.tempoProva}:" id="labeltempoProva"
                                       title="#{msg.titleTempoProvaCadVersao}"/>
                        <p:calendar timeOnly="true" label="#{msg.tempoProva}" locale="#{cadastroVersao.locale}"
                                    value="#{cadastroVersao.versaoCadastro.tempoProvaReal}" required="true" 
                                    requiredMessage="#{msg.campoObrigatorio}" pattern="HH:mm"
                                    id="timeTempoProva" title="#{msg.titleTempoProvaCadVersao}" minHour="1">
                        </p:calendar>
                        <p:message for="timeTempoProva"/>

                        <h:outputLabel value="#{msg.totalQuestoes}:" id="labeltotalQuestoes"
                                       title="#{msg.titleTotalQuestoesCadVersao}"/>
                        <p:inputText   value="#{cadastroVersao.versaoCadastro.totalQuestoesReal}" id="totalQuestoesCad" required="true"
                                       requiredMessage="#{msg.campoObrigatorio}"
                                       label="#{msg.totalQuestoes}">
                            <f:validateLongRange maximum="500" minimum="1"/>
                        </p:inputText>
                        <p:message for="totalQuestoesCad"/>

                        <h:outputLabel value="#{msg.certificacao}:" id="labelCertificacao" title="#{msg.titleCertificacaoVersao}"/>
                        <h:selectOneMenu value="#{cadastroVersao.versaoCadastro.certificacao}" id="selectCertificacao"
                                         title="#{msg.titleCertificacaoVersao}" required="true"
                                         requiredMessage="#{msg.campoObrigatorio}">
                            <f:selectItem itemLabel="#{msg.selecione}" itemValue=""/>
                            <f:selectItems value="#{cadastroVersao.certificacoes}"/>
                            <f:converter converterId="certificacaoConverter"/>
                            <f:ajax render="selectVersaoMother" event="change"></f:ajax>
                        </h:selectOneMenu>
                        <p:message for="selectCertificacao"/>

                        <h:outputLabel value="#{msg.principal}:" id="labelVersaoMaeSelect" 
                                       title="#{msg.titlePrincipalversaoMae}" />
                        <h:selectBooleanCheckbox  value="#{cadastroVersao.versaoCadastro.mother}" id="versaoMaeSelect"  >
                            <f:ajax event="change" render="selectVersaoMother" />
                        </h:selectBooleanCheckbox>  
                        <p:message for="versaoMaeSelect"/>

                        <h:outputLabel value="#{msg.versaoMae}:" id="labelVersaoMae"
                                       title="#{msg.titleVersaoMae}"/>
                        <h:selectOneMenu value="#{cadastroVersao.versaoCadastro.versaoMother}" id="selectVersaoMother"
                                         title="#{msg.titleVersaoMae}" required="#{cadastroVersao.versaoCadastro.mother != true}"
                                         requiredMessage="#{msg.campoObrigatorio}" >
                            <f:selectItem itemLabel="#{msg.selecione}" itemValue=""/>
                            <f:selectItems value="#{cadastroVersao.versoesMother}"/>
                            <f:converter converterId="versaoConverter"/>
                        </h:selectOneMenu>
                        <p:message for="selectVersaoMother"/>

                        <h:outputText value=""/>
                        <h:panelGroup id="buttonGroup">
                            <p:commandLink actionListener="#{cadastroVersao.salvarVersao}" update="conteudoCentralGroup,messages"
                                           title="#{msg.titleButtonSalvarCadVersao}" id="buttonSalvar" styleClass="ui-button_link">
                                <h:graphicImage library="img" name="bt_salvar.png"/>
                            </p:commandLink>
                            <p:spacer width="2" height="2"/>
                            <h:commandButton  title="#{msg.titleButtonCleanCadVersao}" immediate="true" image="/resources/img/bt_limpar_red.png"
                                              id="buttonLimpar"  actionListener="#{cadastroVersao.init}" >
                                <f:ajax render="formCadVersao"></f:ajax>
                            </h:commandButton>
                        </h:panelGroup>

                    </h:panelGrid>
                </h:form>
            </h:panelGroup>

            <p:spacer width="100%" height="15px;"/>

            <h:panelGroup id="tableGroupVersaoCads">
                <h:form id="tableCadVersaoForm">
                    <p:dataTable value="#{cadastroVersao.modelVersoes}" var="versao" id="tableVersao" rows="5" paginator="true"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks}
                                 {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" styleClass="bvb-font"
                                 rowsPerPageTemplate="5,10,15" emptyMessage="#{msg.semRegistrosEcontrados}" >
                        <f:facet name="header">
                            <h:outputText value="#{msg.richTableVersoes}"/>
                        </f:facet>

                        <p:column id="col1" filterBy="#{versao.nome}" headerText="Model" footerText="contains"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnNome}"/>
                            </f:facet>
                            <h:outputText value="#{versao.nome}"/>
                        </p:column>

                        <p:column id="col2"  styleClass="center" sortBy="#{versao.notaParaPassar}">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnMedia}"/>
                            </f:facet>
                            <h:outputText value="#{versao.notaParaPassar}">
                                <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                            </h:outputText>
                        </p:column>

                        <p:column id="col3" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnTempoProva}"/>
                            </f:facet>
                            <h:outputText value="#{versao.tempoProvaReal}">
                                <f:convertDateTime pattern="HH:mm:ss" timeZone="#{initParam.timezone}"/>
                            </h:outputText>
                        </p:column>

                        <p:column id="col4" styleClass="center" sortBy="#{versao.totalQuestoesReal}">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnQuestoes}"/>
                            </f:facet>
                            <h:outputText value="#{versao.totalQuestoesReal}"/>
                        </p:column>

                        <p:column id="col6" styleClass="center" filterBy="#{versao.certificacao.nome}" headerText="Model" footerText="contains"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnCertificacao}"/>
                            </f:facet>
                            <h:outputText value="#{versao.certificacao.nome}"/>
                        </p:column>

                        <p:column id="editarUsuario" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnEditar}"/>
                            </f:facet>
                            <p:commandLink  update="conteudoCentralGroup,messages" title="#{msg.titleButtonPegaEditVersao}" 
                                            id="buttonEditar" styleClass="ui-button_link">
                                <h:graphicImage library="img" name="versao_24_edit.png"/>
                                <f:setPropertyActionListener value="#{versao}" target="#{cadastroVersao.versaoCadastro}" />  
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </h:panelGroup>
        </h:panelGrid>
    </f:subview>
</ui:composition>
